let middlewares = []
let setMiddleWare = function (middlewaresArg) {
  middlewares = middlewaresArg
}
async function compose(ctx) {//只考虑两个中间件
  await middlewares[0](ctx,middlewares[1])//传入next应该是不需要参数的function
}
next[i] = async function(){//next应该是递归
  await middlewares[i](ctx,next[i+1])
}
// function compose(ctx, i) {
//   return async function () {
//     if(middlewares[i]){
//       await middlewares[i](ctx, compose(ctx, i+1))
//     }
//   }
// }


// let fn = compose(ctx, 0)
// fn = async function () {//形成的fn
//   await middlewares[0](ctx, async function () {
//     await middlewares[1](ctx, async function () {
//       await middlewares[2](ctx, async function () {
//       ...
//       })
//     })
//   })
// }
exports.setMiddleWare = setMiddleWare
exports.compose = compose